using System;
using System.Collections.Generic;
using System.Text;

namespace OnlinePlots.Plots.Scales
{
    /// <summary>
    /// Represents a logarithmic scale where [scaled value] = coeff * ( logBase ^ [unscaled value] )
    /// </summary>
    public class LogarithmicScale : Scale
    {
        private double logBase = 10;
        private double coeff = 1;

        /// <summary>
        /// Creates a new instance of logarithmic scale with log base specified and coeff = 1
        /// </summary>
        /// <param name="logBase">Base of logarithm</param>
        public LogarithmicScale(double logBase)
        {
            this.logBase = logBase;
        }

        /// <summary>
        /// Creates a new instance of logarithmic scale with log base and coeff specified
        /// </summary>
        /// <param name="logBase">Base of logarithm</param>
        /// <param name="coeff">Linear quotient of scaling</param> 
        public LogarithmicScale(double logBase, double coeff)
            : this(logBase)
        {
            this.coeff = coeff;
        }

        /// <summary>
        /// Gets or sets base of logarithm
        /// </summary>
        public double LogBase
        {
            get { return logBase; }
            set { logBase = value; }
        }

        /// <summary>
        /// Gets or sets linear quotient of scaling
        /// </summary>
        public double Coeff
        {
            get { return coeff; }
            set { coeff = value; }
        }

        public override double GetScaledValue(double initialValue)
        {
            return Math.Sign(initialValue) * Coeff * Math.Pow(LogBase, Math.Abs(initialValue));
        }

        public override double GetUnscaledValue(double scaledValue)
        {
            return Math.Sign(scaledValue) * Math.Log( Math.Abs(scaledValue) / Coeff, LogBase);
        }
    }
}
